import React, { PureComponent }from 'react';
import PropTypes from 'prop-types';
import { Route, withRouter } from 'dva/router';
import { Button, NavBar, Icon} from 'antd-mobile';

import { MobileAddHoliday, MobileHolidayMenu } from "./mobileHoliday";
import { MobileAddFood, MobileFoodMenu } from "./mobileFood";
import styles from './mobileOperator.less'

class MobileOperator extends PureComponent {
  renderHoliday = () => {
    const { location, history, onSelectDate } = this.props;
    const rightContent = location.pathname.includes('add') ?
      [<span key='add11' onClick={() => {history.push('/holiday/menu')}}>记录</span>]:
      [<span key='add222' onClick={() => {history.push('/holiday/add')}}>请假</span>];
    return(
      <div>
        <NavBar
          icon={<Icon type="left" />}
          onLeftClick={this.props.goBack}
          rightContent={rightContent}
        >
          请假
        </NavBar>
        <Route path='/holiday/add' render={() => (<MobileAddHoliday history={history} goBack={this.props.goBack} onSelectDate={onSelectDate}/>)}/>
        <Route path='/holiday/menu' component={MobileHolidayMenu}/>
      </div>
    )
  };
  renderBookFood = () => {
    const { location, history, onSelectDate } = this.props;
    const rightContent = location.pathname.includes('add') ?
      [<span key='12311' onClick={() => {history.push('/bookfood/menu')}}>记录</span>]:
      [<span key='adaddad222' onClick={() => {history.push('/bookfood/add')}}>报餐</span>];
    return(
      <div>
        <NavBar
          icon={<Icon type="left" />}
          onLeftClick={this.props.goBack}
          rightContent={rightContent}
        >
          报餐
        </NavBar>
        <Route path='/bookfood/add' render={() => (<MobileAddFood history={history} goBack={this.props.goBack} onSelectDate={onSelectDate}/>)}/>
        <Route path='/bookfood/menu' component={MobileFoodMenu}/>
      </div>
    );
  };
  render() {
    return (
      <div>
        <Route path='/holiday' render={this.renderHoliday} />
        <Route path='/bookfood' render={this.renderBookFood} />
      </div>
    );
  }
}

export default withRouter(MobileOperator)
